-
Notifications
You must be signed in to change notification settings - Fork 348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTTPCLIENT-2159: Invalid handling of charset content type parameter #483
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use a builder for ContenType instead of piling on constructors or factory methods.
httpcore5/src/test/java/org/apache/hc/core5/http/TestContentType.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR does not put the description on the MIME types into consideration pointed out in HTTPCLIENT-2159.
httpcore5/src/main/java/org/apache/hc/core5/http/ContentType.java
Outdated
Show resolved
Hide resolved
8d2d6ff
to
034fb48
Compare
HI @michael-o |
HI @garydgregory |
Will do tomorrow with a sober mind. |
Hi @arturobernalg I do take your point that it could be done in a separate PR if that PR happens first. If we agree on implementing a builder, I can volunteer to do it unless you'd rather do it. |
httpcore5/src/main/java/org/apache/hc/core5/http/ContentType.java
Outdated
Show resolved
Hide resolved
httpcore5/src/test/java/org/apache/hc/core5/http/TestContentType.java
Outdated
Show resolved
Hide resolved
httpcore5/src/test/java/org/apache/hc/core5/http/TestContentType.java
Outdated
Show resolved
Hide resolved
httpcore5/src/main/java/org/apache/hc/core5/http/ContentType.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a few comments.
63a1a85
to
9b659f5
Compare
HI @garydgregory |
d39f85d
to
c679083
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code is fine for me now, but the title is wrong. The actual report does not relate to any redirects at all. Please change and we are good to merge.
done |
MessageSupport.formatParameters(buf, this.params); | ||
} else if (this.charset != null) { | ||
boolean first = true; | ||
for (final NameValuePair param : params) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arturobernalg One could use normal index loop here and avoid this super ugly first
variable (and likely be more memory efficient).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HI @ok2c
The ´first´ variable is needed to handle the condition correctly, ensuring that parameters are properly separated while avoiding an extra "; " in cases where the charset is implicit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HI @ok2c The ´first´ variable is needed to handle the condition correctly, ensuring that parameters are properly separated while avoiding an extra "; " in cases where the charset is implicit.
@arturobernalg You are right. Indeed, an index variable would not work here. Still, I would avoid using for each
loops in HC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about the join API https://docs.oracle.com/javase/8/docs/api/java/util/StringJoiner.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ok2c fair enough. changed
…media types * Updated ContentType to ensure that no charset is included for media types like application/octet-stream, multipart/form-data, and image/*, which do not require a charset as per the RFC. * Refactored the toString() method to properly handle the omission of charset for these media types. * Adjusted the creation methods to better handle implicit charsets and added validation for reserved characters in MIME types.
e48a227
to
185778f
Compare
This PR is an attempt to mitigate the issues highlighted in HTTPCLIENT-2159,. The root problem stems from how we are incorrectly handling certain content types by attaching charset parameters when they shouldn't have one. This update adjusts the way the Content-Type header handles specific cases, ensuring compliance with relevant specifications.